//
//  SingInViewController.m
//  Restaurant
//
//  Created by Tibby on 11/4/15.
//  Copyright © 2015 Tibby. All rights reserved.
//

#import "SingInViewController.h"
#import "MainViewController.h"
#import "SignUpViewController.h"
#import "ResetPasswordViewController.h"
@interface SingInViewController ()

@property (strong, nonatomic) UILabel* usernameLabel;
@property (strong, nonatomic) UILabel* userPassLabel;
@property (strong, nonatomic) UITextField* usernameTextField;
@property (strong, nonatomic) UITextField* userPassTextField;
@property (strong, nonatomic) UIButton* signInButton;
@property (strong, nonatomic) UIButton* signUpButton;
@property (strong, nonatomic) UIButton* resetpassButton;

@end

@implementation SingInViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"SigIn";
    [self initViews];
    [self initLayout];
    [self setButtonListener];
}

- (void)initViews{
    
    self.usernameLabel = [UILabel new];
    self.usernameLabel.text = @"username";
    self.usernameLabel.font = [UIFont systemFontOfSize:16];
    self.usernameLabel.backgroundColor = [UIColor blueColor];
    
    self.userPassLabel = [UILabel new];
    self.userPassLabel.text = @"password";
    self.userPassLabel.font = [UIFont systemFontOfSize:16];
    self.userPassLabel.backgroundColor = [UIColor blueColor];
    
    self.usernameTextField = [UITextField new];
    self.usernameTextField.placeholder = @"please enter your username";
    self.usernameTextField.backgroundColor = [UIColor redColor];
    
    self.userPassTextField = [UITextField new];
    self.userPassTextField.placeholder = @"please enter your password";
    self.userPassTextField.secureTextEntry = YES;
    self.userPassTextField.backgroundColor = [UIColor redColor];
    
    self.signInButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.signInButton setTitle:@"SignIn" forState:UIControlStateNormal];
    self.signInButton.backgroundColor = [UIColor greenColor];
    
    self.signUpButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.signUpButton setTitle:@"SignUp" forState:UIControlStateNormal];
    self.signUpButton.backgroundColor = [UIColor greenColor];
    
    self.resetpassButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.resetpassButton setTitle:@"Reset Password" forState:UIControlStateNormal];
    self.resetpassButton.backgroundColor = [UIColor greenColor];

    
    [self.view addSubview:self.usernameLabel];
    [self.view addSubview:self.userPassLabel];
    [self.view addSubview:self.usernameTextField];
    [self.view addSubview:self.userPassTextField];
    [self.view addSubview:self.signInButton];
    [self.view addSubview:self.signUpButton];
    [self.view addSubview:self.resetpassButton];
    
    for (UIView* view in self.view.subviews) {
        view.translatesAutoresizingMaskIntoConstraints = NO;
    }
}

- (void)initLayout{
    NSDictionary* views = @{@"usernameLabel":self.usernameLabel,@"userPassLabel":self.userPassLabel,@"usernameTextField":self.usernameTextField,@"userPasswordTextField":self.userPassTextField,@"signInButton":self.signInButton,@"signUpButton":self.signUpButton,@"resetPasswordButton":self.resetpassButton};
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[usernameLabel(==80)]-[usernameTextField]-10-|" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[userPassLabel(==80)]-[userPasswordTextField]-10-|" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[signInButton]-10-|" options:0 metrics:nil views:views]];
//    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[signUpButton]-10-[resetPasswordButton]-10-|" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[signUpButton(==120)]" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[resetPasswordButton(==120)]-10-|" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-80-[usernameLabel(==50)]-20-[userPassLabel(==50)]-20-[signInButton(==50)]-[signUpButton(==50)]" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-80-[usernameTextField(==50)]-20-[userPasswordTextField(==50)]-20-[signInButton]-[resetPasswordButton(==50)]" options:0 metrics:nil views:views]];
}

- (void)setButtonListener{
    [self.signInButton addTarget:self action:@selector(signIn) forControlEvents:UIControlEventTouchUpInside];
    [self.signUpButton addTarget:self action:@selector(signUp) forControlEvents:UIControlEventTouchUpInside];
    [self.resetpassButton addTarget:self action:@selector(resetPassword) forControlEvents:UIControlEventTouchUpInside];
}

- (void)signIn{
    MainViewController* mainController = [MainViewController new];
    [self.navigationController pushViewController:mainController animated:YES];
}

- (void)signUp{
    SignUpViewController* signUpViewController = [SignUpViewController new];
    [self.navigationController pushViewController:signUpViewController animated:YES];
}

- (void)resetPassword{
    ResetPasswordViewController* resetPasswordViewController = [ResetPasswordViewController new];
    [self.navigationController pushViewController:resetPasswordViewController animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
